<?php
    $basename = preg_replace('/^.+[\\\\\\/]/', '', $_SERVER['PHP_SELF'] );
    $curuserlevel = $_SESSION['userlevel'];
    function template_headtag($title, $style = TRUE, $path = '') {
        global $basename;
        $title = strip_tags($title);
        echo "
            <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
            <html>
             
            <head>
            <title>EightyThree - $title</title>
            <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
            ";
        if ($style) {
            echo "
                <link rel='stylesheet' href='style.css' type='text/css' media='screen' />
                <link rel='icon' href='images/arigel.ico' type='image/x-icon' />
                ";
        }
        echo "
            </head>
            ";
        echo "<body>";
         
    }
    function template_header() {
        echo "<div id='outer'>";
        echo "<div id='header'>";
        echo "<div class='betaversion'><img src='images/content/bug.png' title='Hic Sunt Dracones' />&nbsp;beta version</div>";
    echo "<a href='main.php'><img src='images/content/EightyThree.png' alt='EightyThree Logo' title='Go to Main Page' /></a>"; //edit this line to change header name.
        echo "</div>"; // Close Header Div
         
    }
    function template_left() {
        global $curuserlevel, $userlevel;
        if ($curuserlevel > 0) {
            echo "<div id='navigation'>";
            echo "<!-- start of navigation -->";
            if ($curuserlevel >= $userlevel['main']) {
                echo "<a href='main.php' title='Main Page' class=floatleft><img src='images/navbar/home.png' height='16' width='16' border='0' alt='Home' />Home</a>";
            }
            if ($curuserlevel >= $userlevel['main']) {
                echo "<a href='tracking.php' title='See list of all Files in Repository' class=floatleft><img src='images/navbar/database.png' height='16' width='16' border='0' alt='Tracking' />Files</a>";
            }
            
            if ($curuserlevel >= $userlevel['addfile']) {
                echo "<a href='addfile.php' title='Add a new file to track' class='floatleft'><img src='images/navbar/addfile.png' height='16' width='16' border='0' alt='Add file' />Add file</a>";
            }
            if ($curuserlevel >= $userlevel['adddir']) {
                echo "<a href='adddir.php' title='Add a new directory to track' class='floatleft'><img src='images/navbar/adddir.png' height='16' width='16' border='0' alt='Add Directory' />Add Directory </a>";
            }
            if ($curuserlevel >= $userlevel['upddateallfiles']) {
                echo "<a href='updateallfiles.php' title='Update All Files in Database' class='floatleft'><img src='images/navbar/updateall.png' height='16' width='16' border='0' alt='Update all files' />Update</a>";
            }
            echo "<a href='logout.php' title='Logout of EightyThree' class='floatright'><img src='images/navbar/logout.png' height='16' width='16' border='0' alt='Logout' />Logout</a>";
            
            if ($curuserlevel >= $userlevel['createuser']) {
                echo "<a href='adduser.php' title='Add a new user' class='floatright'><img src='images/navbar/adduser.png' height='16' width='16' border='0' alt='>Add User' />Add User</a>";
            }
            if ($curuserlevel >= $userlevel['listusers']) {
                echo "<a href='listusers.php' title='List of All Users' class='floatright'><img src='images/navbar/user.png' height='16' width='16' border='0' alt='List Users' />List Users</a>";
            }
            echo "<!-- end of navigation -->";
            echo "</div>
            <div id='nav-back'>&nbsp;</div>";
        }
        echo "<div id='clearheader'></div>
            <div id='content'>";
    }
     
    function template_footer() {
        echo "
            </div>
            <div id='clearfooter'></div>
            </div>
             
            <div id='footer'>
                        
            <div style='float:right;'><a href='http://www.arigel.com' title='Go to Arigel Website'><img src='images/footer/logo.png' border=0 alt='Arigel Open Source logo' /></a></div>
            </div>
            <!-- EightyThree - 1983 -->
            <!-- This is version 0.1 Beta -->
            
            <!-- EightyThree is released under GPL v3. EightyThree is owned by Arigel -->
            </body>
            </html>
            ";
    }
     
    function loginbox($caplockcheck = TRUE) {
        if ($caplockcheck) {
            echo "<script language='JavaScript' type='text/javascript'>";
            echo "function checkcapLock(e){
                kc = e.keyCode?e.keyCode:e.which;
                sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
                if (((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
                document.getElementById('capslockwarning').style.visibility = 'visible';
                else
                document.getElementById('capslockwarning').style.visibility = 'hidden';
                }";
            echo "</script>";
        }
        echo "
            <br />
            <form method='post' action='login.php'>
            <table border='0'>
            <tr>
            <td> Username : </td>
            <td><input type='text' name='username' /> </td>
            </tr>
            <tr>
            <td> Password :  </td>
            <td> <input type='password' name='password' onkeypress='checkcapLock(event)' />
            </td>
            </tr>
            </table><br />
            <input type='image' src='images/add/arrows.gif' name='submit' value='Login' />
            </form>
            ";
         
        if ($caplockcheck) {
            echo "<br /><div id='capslockwarning' style='border : #ff0000 solid 1px; padding:4px; text-align : center; visibility : hidden; width: 240px;'><img src='images/messagebox_warning.png' />  WARNING : Caps Lock is on.</div>";
        }
        echo "
            
            ";
    }
     
    function errorbox($message, $size = '200px', $alignment = 'center') {
         
        echo "<div align='$alignment'> <div class='alert' style='width:$size;'>$message</div></div>";
    }
    function errorpage($message, $title, $path = '' , $size = '200px', $alignment = 'center') {
        template_headtag($title);
        template_header();
        template_left();
        echo "<br />";
        errorbox($message, $size, $alignment);
        echo "<div align='center'><a href='javascript: history.go(-1)'>Back</a></div>";
        template_footer();
    }
     
?>
